<!doctype html>
<html lang="en">
{include file='public/header'}
<style>
    .layui-nav-child .active{
        background-color: #009688;
    }
    .layui-nav-child .active a{
        color: #fff;
    }
    #launch,#pitcher,#officialAccount,#scale,.fast-add,#filiale_pitcher,#statisticsIndex,#byPeopleIndex{
        display: none;
    }
    .passwordBox .layui-form-label{
        width: 70px;
        padding: 9px 10px;
    }
    .layui-input-block{
        margin-left: 90px;
    }
</style>
<body>
    <!-- 顶部开始 -->
    <div class="container">
        <div class="logo"><a href="./index.html">CPS</a></div>
        <div class="left_open">
            <i title="展开左侧栏" class="iconfont">&#xe699;</i>
        </div>
        <ul class="layui-nav left fast-add" lay-filter="">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    
                </a>
                <dl class="layui-nav-child" style="max-height:500px;overflow-y: scroll;" id="account_select">
                    
                </dl>
            </li>
        </ul>
        <ul class="layui-nav right" lay-filter="">
            <li class="layui-nav-item">
                <a href="javascript:;" id="cps_user_name">
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" id="changePassword">修改密码</a></dd>
                    <dd><a href="javascript:;" onclick="logout()">退出</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item to-index"><a href="/cps/index/index.html">首页</a></li>
        </ul>

    </div>
    <!-- 顶部结束 -->
    <!-- 中部开始 -->
    <!-- 左侧菜单开始 -->
    <div class="left-nav">
        <div id="side-nav">
            <ul class="layui-nav layui-nav-tree left_nav_tree">
                <li class="layui-nav-item">
                    <a href="javascript:;">数据统计</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/index/statistics"><a _href="/cps/index/statistics">订单统计</a></dd>
                        <dd tab-id="/cps/index/videoIndex"><a _href="/cps/index/videoIndex">短剧统计</a></dd>
                        <dd id="statisticsIndex" tab-id="/cps/user/statisticsIndex"><a _href="/cps/user/statisticsIndex">用户统计</a></dd>
                        <dd tab-id="/cps/recharge/perCapita"><a _href="/cps/recharge/perCapita">充值人均统计</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">短剧推广</a>
                    <dl class="layui-nav-child">
                        <!-- <dd tab-id="/cps/account/index"><a _href="/cps/account/index">投放账号管理</a></dd> -->
                        <dd tab-id="/cps/video/index"><a _href="/cps/video/index">短剧中心</a></dd>
                        <dd tab-id="/cps/link/index"><a _href="/cps/link/index">推广链接</a></dd>
                        <!-- <dd tab-id="/cps/video/configIndex"><a _href="/cps/video/configIndex">自定义短剧收费</a></dd> -->
                        <dd tab-id="/cps/recharge/default"><a _href="/cps/recharge/default">默认充值数据</a></dd>
                        <!-- <dd tab-id="/cps/recharge/index"><a _href="/cps/recharge/index">自定义充值模板</a></dd> -->
                        <dd tab-id="/cps/back/index"><a _href="/cps/back/index">回传配置</a></dd>
                        <dd tab-id="/cps/customRechargeTemplate/index"><a _href="/cps/customRechargeTemplate/index">自定义收费设置</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">用户管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/user/index"><a _href="/cps/user/index">粉丝管理</a></dd>
                        <!-- <dd tab-id="/cps/user/analysis"><a _href="/cps/user/analysis">用户分析</a></dd> -->
                    </dl>
                </li>
                <li class="layui-nav-item" id="officialAccount">
                    <a href="javascript:;">公众号管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/officialAccount/info"><a _href="/cps/officialAccount/info">公众号设置</a></dd>
                        <dd tab-id="/cps/officialAccount/menu"><a _href="/cps/officialAccount/menu">菜单设置</a></dd>
                        <dd tab-id="/cps/keyword/index"><a _href="/cps/keyword/index">关键字回复</a></dd>
                        <dd tab-id="/cps/officialAccount/follow"><a _href="/cps/officialAccount/follow">被关注回复</a></dd>
                        <dd tab-id="/cps/officialAccount/sign"><a _href="/cps/officialAccount/sign">签到回复</a></dd>
                        <dd tab-id="/cps/video/set"><a _href="/cps/video/set">智能推送</a></dd>
                    </dl>
                </li>
                   <!-- 素材管理 -->
                <li class="layui-nav-item" id="material">
                    <a href="javascript:;">素材管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/material/index"><a _href="/cps/material/index">素材列表</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">订单管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/order/detailed"><a _href="/cps/order/detailed">订单明细</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">回传</a>
                    <dl class="layui-nav-child">
                        <!-- <dd tab-id="/cps/tencent/index"><a _href="/cps/tencent/index">腾讯创建数据源</a></dd> -->
                        <dd tab-id="/cps/back/alreadyReturn"><a _href="/cps/back/alreadyReturn">已回传数据</a></dd>
                        <dd tab-id="/cps/back/notReturn"><a _href="/cps/back/notReturn">未回传数据</a></dd>
                        <dd tab-id="/cps/back/unpaidUserManualReturn"><a _href="/cps/back/unpaidUserManualReturn">未充值用户列表</a></dd>
                        <dd tab-id="/cps/back/manualReturnRecordIndex"><a _href="/cps/back/manualReturnRecordIndex">未充值用户回传列表</a></dd>
                    </dl>
                </li>
                <!-- 普通投手 -->
                <li class="layui-nav-item" id="launch">
                    <a href="javascript:;">投放管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/launch/overview"><a _href="/cps/launch/overview">投放总览</a></dd>
                        <dd tab-id="/cps/launch/realTime"><a _href="/cps/launch/realTime">抖音今日实时在投</a></dd>
                        <dd tab-id="/cps/launch/kwaiRealTime"><a _href="/cps/launch/kwaiRealTime">快手今日实时在投</a></dd>
                        <dd tab-id="/cps/launch/baiduRealTime"><a _href="/cps/launch/baiduRealTime">百度今日实时在投</a></dd>
                        <dd tab-id="/cps/launch/tencentRealTime"><a _href="/cps/launch/tencentRealTime">腾讯今日实时在投</a></dd>
                        <!-- <dd tab-id="/cps/launch/byVideo"><a _href="/cps/launch/byVideo">按短剧统计</a></dd>
                        <dd id="byPeopleIndex" tab-id="/cps/launch/byPeopleIndex"><a _href="/cps/launch/byPeopleIndex">按负责人统计</a></dd> -->
                        <!-- <dd tab-id="/cps/launch/byVideoDiscount"><a _href="/cps/launch/byVideoDiscount">按短剧统计（95折）</a></dd> -->
                    </dl>
                </li>
                <!-- 分销商 -->
                <li class="layui-nav-item" id="pitcher">
                    <a href="javascript:;">投放管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/pitcher/index"><a _href="/cps/pitcher/index">投手管理</a></dd>
                        <dd tab-id="/cps/pitcher/backSetInfo"><a _href="/cps/pitcher/backSetInfo">回传设置</a></dd>
                    </dl>
                </li>
                <!-- 分公司负责人 -->
                <li class="layui-nav-item" id="filiale_pitcher">
                    <a href="javascript:;">投放管理</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/filiale_pitcher/index"><a _href="/cps/pitcher/index">投手管理</a></dd>
                        <dd tab-id="/cps/filiale_pitcher/backSetInfo"><a _href="/cps/pitcher/backSetInfo">回传设置</a></dd>
                        <dd tab-id="/cps/filiale_pitcher/overview"><a _href="/cps/launch/overview">投放总览</a></dd>
                        <dd tab-id="/cps/filiale_pitcher/realTime"><a _href="/cps/launch/realTime">抖音今日实时在投</a></dd>
                        <dd tab-id="/cps/filiale_pitcher/kwaiRealTime"><a _href="/cps/launch/kwaiRealTime">快手今日实时在投</a></dd>
                        <dd tab-id="/cps/filiale_pitcher/baiduRealTime"><a _href="/cps/launch/baiduRealTime">百度今日实时在投</a></dd>
                        <dd tab-id="/cps/launch/tencentRealTime"><a _href="/cps/launch/tencentRealTime">腾讯今日实时在投</a></dd>
                        <!-- <dd tab-id="/cps/filiale_pitcher/byVideo"><a _href="/cps/launch/byVideo">按短剧统计</a></dd>
                        <dd tab-id="/cps/filiale_pitcher/byPeopleIndex"><a _href="/cps/launch/byPeopleIndex">按负责人统计</a></dd> -->
                        <!-- <dd tab-id="/cps/filiale_pitcher/byVideoDiscount"><a _href="/cps/launch/byVideoDiscount">按短剧统计（95折）</a></dd> -->
                    </dl>
                </li>
                <li class="layui-nav-item" id="scale">
                    <a href="javascript:;">分销</a>
                    <dl class="layui-nav-child">
                        <dd tab-id="/cps/distribution/dividedStatisticsIndex"><a _href="/cps/distribution/dividedStatisticsIndex">分销商分成统计</a></dd>
                        <dd tab-id="/cps/distribution/distributionSettlementIndex"><a _href="/cps/distribution/distributionSettlementIndex">分销结算</a></dd>
                        <dd tab-id="/cps/distribution/smsSharingIndex"><a _href="/cps/distribution/smsSharingIndex">分销商H5短信分成列表</a></dd>
                    </dl>
                </li>
                
            </ul>
        </div>
    </div>
    <!-- <div class="x-slide_left"></div> -->
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
            <ul class="layui-tab-title">
                <li class="home"><i class="layui-icon">&#xe68e;</i>我的桌面</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <iframe src='' id="statistics_iframe" frameborder="0" scrolling="yes" class="x-iframe"></iframe>
                </div>
            </div>
        </div>
    </div>
    <div class="page-content-bg"></div>
    <!-- 右侧主体结束 -->
    <!-- 中部结束 -->
    <!-- 底部开始 -->
    <div class="footer">
        <div class="copyright">Copyright ©<script>document.write(new Date().getFullYear())</script> x-admin v2.3 All Rights Reserved</div>
    </div>
    <!-- 底部结束 -->

    <script>    
        // 切换公众号
        function switchOfficialAccount(official_account_id){
            Ajax('/cps/index/switchOfficialAccount',{official_account_id},'get').then(result =>{
                if (result.code === 200) {
                    let message = JSON.parse(localStorage.getItem('cpsMessage'));
                    message.cps_used_official_account_id = result.data.cps_used_official_account_id
                    localStorage.setItem('cpsMessage',JSON.stringify(message))
                    layer.msg(result.message, {
                        icon: 6
                    }, function () {
                        location.reload()          
                    });
                }
            });
        }
        console.log(JSON.parse(user_login_message))
        var is_distributor,//是否分销商
            pid,//上级id 分销下的投手 或者 分公司下的投手
            is_branch_office_manage,//分公司负责人
            is_branch_office_pitcher;//是否分公司下的投手
        Ajax('/cps/distribution/detail', {}).then(result => {
            localStorage.setItem('user_message',JSON.stringify(result.data))
            is_distributor = result.data.is_distributor;
            pid = result.data.pid ?? '';
            is_branch_office_manage = result.data.is_branch_office_manage;
            is_branch_office_pitcher = result.data.is_branch_office_pitcher;
            if(is_distributor === 1){
                // 上级ID为空、is_distributor是1 代表是分销商
                if(!pid){
                    // 展示投放管理
                    $('#pitcher').show()
                    // 展示分销 
                    $('#scale').show() 
                }
                $('.fast-add').show()
                $("#statisticsIndex").show()
            }else if(is_branch_office_manage === 1){
                // 分公司负责人
                // 隐藏下拉选择公众号
                $('.fast-add').hide()
                // 展示投放管理
                $("#filiale_pitcher").show()
            }else if (is_branch_office_pitcher === 1){
                // 分公司投手
                $("#launch").show()
                $('.fast-add').show()
            }else{
                // 普通投手
                if(!pid){
                    // 展示投放管理
                    $('#launch').show()
                    // 展示公众号管理
                    $('#officialAccount').show()
                }
                $('.fast-add').show()
                $("#statisticsIndex").show()
                // cps总账号
                if(JSON.parse(user_login_message).id === 13){
                    $("#byPeopleIndex").show()
                }
            }
        });
        layui.use(["form", "layer"], function () {
            var form = layui.form,
                layer = layui.layer;
            $('#changePassword').click(function(){
                layer.open({
                    type: 1,
                    title: '修改密码',
                    btn: ['保存', '取消'],
                    maxHeight: '500',
                    content: `
                        <div class="x-body" >
                            <form class="layui-form passwordBox" lay-filter="changePassword">
                                <div class="layui-form-item">
                                    <label class="layui-form-label ">
                                        <span class="x-red">*</span>原密码
                                    </label>
                                    <div class="layui-input-block">
                                        <input type="password" name="original_password" placeholder="原密码" autocomplete="off" class="layui-input" value="" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">
                                        <span class="x-red">*</span>新密码
                                    </label>
                                    <div class="layui-input-block">
                                        <input type="password" name="password" placeholder="新密码" autocomplete="off" class="layui-input" value="" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">
                                        <span class="x-red">*</span>确认密码
                                    </label>
                                    <div class="layui-input-block">
                                        <input type="password" name="confirm_password" placeholder="确认密码" autocomplete="off" class="layui-input" value="" lay-verify="confirm_password"/>
                                    </div>
                                </div>
                            </form>
                        </div>
                    `,
                    yes: function(layMask){
                        let data = form.val("changePassword");
                        if(data.password != data.confirm_password){
                            layer.msg('两次密码不一致', {
                                icon: 5,
                                time:1000
                            });
                            return;
                        } 
                        Ajax('/cps/user/chargePass',data).then(result =>{
                            layer.msg(result.message, {
                                icon: 6
                            }, function () {
                                logout()
                            });
                        });
                    }
                });
            })
        });

        // 退出登录
        function logout(){
            Ajax('/cps/login/logout',{}).then(data => {
                localStorage.removeItem('cpsToken')
                localStorage.removeItem('cpsMessage')
                layer.msg('退出成功!',{icon:1,time:1000},function () {
                    jumpUrl('/cps/login/index')
                });
            });
        }
        
        // 渲染公众号下拉
        var cpsMessage = JSON.parse(localStorage.getItem('cpsMessage'));
        var cps_official_accounts_data = cpsMessage.official_accounts_data;
        let cps_official_accounts_data_template = '',now_cps_official_accounts;
        cps_official_accounts_data.forEach(item=>{
            cps_official_accounts_data_template+= `
                <dd ${item.id == cpsMessage.cps_used_official_account_id ? 'class="active"' : ''}>
                    <a href="javascript:;" onclick="switchOfficialAccount('${item.id}')">${item.name}</a>
                </dd>
            `;
            if(item.id == cpsMessage.cps_used_official_account_id){
                now_cps_official_accounts = item.name;
            }
        })
        $(".fast-add .layui-nav-item a").html(now_cps_official_accounts)
        $("#account_select").html(cps_official_accounts_data_template)
        $('#statistics_iframe').attr('src','/cps/index/statistics?token='+token)
        $('#cps_user_name').html(cpsMessage.name)

        $(function(){
            setCard({Name:cpsMessage.name,WWID:"比翼鸟"});
        })
        window.onresize = debounce(function(){
            $('.watermark').remove()
            setCard({Name:cpsMessage.name,WWID:"比翼鸟"});
        },500)
    </script>
</body>

</html>